<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Docker 镜像代理加速</title>
    <link rel="icon" href="https://cdn.jsdelivr.net/gh/dqzboy/Blog-Image/BlogCourse/docker-proxy.png" type="image/png">
    <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
    <style>
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Lato', 'Helvetica', 'Arial', sans-serif;
            line-height: 1.6;
            color: #24292e;
            margin: 0;
            padding: 0;
            background-color: #f6f8fa;
            display: flex;
            flex-direction: column;
            min-height: 100vh;
        }
        .header {
            background-color: #ffffff;
            box-shadow: 0 1px 3px rgba(0,0,0,0.1);
            padding: 10px 30px;
            display: flex;
            justify-content: center;
            align-items: center;
            flex-wrap: wrap;
        }
        .header-content {
            display: flex;
            align-items: center;
            justify-content: space-between;
            width: 100%;
            max-width: 1200px;
        }
        .logo {
            max-height: 70px;
        }
        .logo-link {
            display: inline-block;
            text-decoration: none;
        }

        .logo-link:hover {
            opacity: 0.8;
            transition: opacity 0.3s ease;
        }
        .nav-menu {
            display: flex;
            gap: 10px;
            font-size: 18px;
            margin-left: auto;
        }

        .nav-menu a {
            color: #0366d6;
            text-decoration: none;
            font-weight: 500;
            transition: all 0.3s ease;
            padding: 8px 12px;
            border-radius: 5px;
            position: relative;
        }

        .nav-menu a:hover {
            color: #0366d6;
            background-color: rgba(3, 102, 214, 0.1);
        }

        .nav-menu a::after {
            content: '';
            position: absolute;
            width: 0;
            height: 2px;
            bottom: 0;
            left: 50%;
            background-color: #0366d6;
            transition: all 0.3s ease;
        }

        .nav-menu a:hover::after {
            width: 100%;
            left: 0;
        }
        .container {
            max-width: 800px;
            width: 90%;
            margin: 20px auto;
            background: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            flex-grow: 1;
            position: relative;
        }
        h1, h2 {
            border-bottom: 2px solid #eaecef;
            padding-bottom: 0.5em;
            margin-bottom: 1em;
            color: #0366d6;
        }
        .input-group {
            margin-bottom: 30px;
            display: flex;
            flex-direction: column;
        }
        input[type="text"] {
            width: 100%;
            padding: 12px;
            font-size: 16px;
            border: 1px solid #d1d5da;
            border-radius: 4px;
            margin-bottom: 15px;
            box-sizing: border-box;
        }
        button {
            padding: 12px 20px;
            background-color: #2ea44f;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
            transition: background-color 0.3s;
            align-self: flex-start;
        }
        button:hover {
            background-color: #2c974b;
        }
        .carousel {
            width: 100%;
            height: 300px;
            display: flex;
            justify-content: center;
            align-items: center;
            perspective: 1000px;
            position: relative;
            margin-top: 30px;
            margin-bottom: 30px;
        }
        .carousel-inner {
            position: relative;
            width: 50%;
            height: 100%;
            transform-style: preserve-3d;
            transform: translateZ(-300px);
            transition: transform 1s;
        }
        .carousel-item {
            position: absolute;
            width: 70%;
            height: 100%;
            left: 50%;
            top: 0;
            transform-origin: center center;
            transition: transform 1s, opacity 1s;
            opacity: 0.5;
        }
        .carousel-item.active {
            transform: translateX(-50%) translateZ(300px);
            opacity: 1;
        }
        .carousel-item.left {
            transform: translateX(-150%) translateZ(100px) rotateY(30deg);
        }
        .carousel-item.right {
            transform: translateX(50%) translateZ(100px) rotateY(-30deg);
        }
        .carousel-control {
            position: absolute;
            top: 50%;
            transform: translateY(-50%);
            font-size: 2em;
            cursor: pointer;
        }
        .carousel-control.left {
            left: 10px;
        }
        .carousel-control.right {
            right: 10px;
        }
        pre {
            background-color: #f6f8fa;
            border-radius: 4px;
            padding: 16px;
            overflow: auto;
            font-size: 14px;
            border: 1px solid #e1e4e8;
            position: relative;
        }
        .copy-btn {
            position: absolute;
            top: 8px;
            right: 8px;
            padding: 6px 12px;
            font-size: 12px;
            background-color: #f0f0f0;
            color: #333;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            transition: background-color 0.3s, color 0.3s;
            font-family: 'Arial', sans-serif;
            font-weight: 500;
            border-radius: 12px;
        }
        .copy-btn:hover {
            background-color: #e0e0e0;
            color: #000;
        }
        .step {
            margin-bottom: 25px;
            background-color: #fff;
            border: 1px solid #e1e4e8;
            border-radius: 6px;
            padding: 20px;
        }
        .step h3 {
            margin-top: 0;
            color: #24292e;
        }
        .footer {
            background-color: #f6f8fa;
            color: #6a737d;
            text-align: center;
            padding: 20px;
            margin-top: 20px;
        }
        .footer a {
            color: #58a6ff;
            text-decoration: none;
        }
        .footer a:hover {
            text-decoration: underline;
        }
        #backToTopBtn {
            display: none;
            position: fixed;
            bottom: 20px;
            right: 20px;
            z-index: 100;
            font-size: 16px;
            padding: 10px;
            background-color: #0366d6;
            color: white;
            border: none;
            border-radius: 50%;
            cursor: pointer;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        #backToTopBtn:hover {
            background-color: #0256b9;
        }
        #backToTopBtn::after {
            content: '返回顶部';
            display: none;
            position: absolute;
            bottom: 50px;
            right: 0;
            padding: 5px 10px;
            background-color: #333;
            color: white;
            border-radius: 5px;
            white-space: nowrap;
        }
        #backToTopBtn:hover::after {
            display: block;
        }
        @media (max-width: 768px) {
            .nav-menu {
                display: none;
                flex-direction: column;
                position: absolute;
                top: 100%;
                left: 0;
                width: 100%;
                background-color: #ffffff;
                box-shadow: 0 2px 5px rgba(0,0,0,0.1);
                padding: 10px 0;
            }

            .nav-menu.active {
                display: flex;
            }

            .nav-menu a {
                padding: 10px 20px;
            }

            .menu-toggle {
                display: block;
                font-size: 24px;
                cursor: pointer;
            }
        }

        @media (min-width: 769px) {
            .menu-toggle {
                display: none;
            }
        }
        .notification {
            display: none;
            position: absolute;
            top: 7px;
            left: 87%;
            transform: translateX(-50%);
            background-color: #333;
            color: #fff;
            padding: 5px 10px;
            border-radius: 5px;
            font-size: 12px;
            opacity: 0;
            transition: opacity 0.5s ease-in-out;
            z-index: 1000;
        }

        /* 搜索样式 */
        .search-container {
            margin-top: 20px;
        }
        #searchResults {
            margin-top: 20px;
            display: none;
        }
        .search-result-item {
            border: 1px solid #e1e4e8;
            border-radius: 6px;
            padding: 10px;
            margin-bottom: 10px;
        }
        .search-result-item h3 {
            margin-top: 0;
        }
        .search-result-item p {
            margin-bottom: 5px;
        }
        .use-image-btn {
            background-color: #0366d6;
            color: white;
            border: none;
            padding: 5px 10px;
            border-radius: 4px;
            cursor: pointer;
        }
        .use-image-btn:hover {
            background-color: #0256b9;
        }
        .official-image {
            background-color: #e6f3ff;
            border-left: 5px solid #0366d6;
            padding-left: 15px;
        }
        .search-result-item {
            margin-bottom: 15px;
            padding: 10px;
            border: 1px solid #e1e4e8;
            border-radius: 6px;
        }
        .search-result-item h3 {
            margin-top: 0;
            color: #0366d6;
        }
        .official-badge {
            background-color: #28a745;
            color: white;
            padding: 2px 5px;
            border-radius: 3px;
            font-size: 12px;
            margin-left: 10px;
        }
        .stars {
            color: #586069;
            font-size: 14px;
        }
        .tab-container {
            display: flex;
            justify-content: center;
            margin-bottom: 20px;
        }
        .tab {
            padding: 10px 20px;
            cursor: pointer;
            border: 1px solid #d1d5da;
            background-color: #f6f8fa;
            color: #24292e;
        }
        .tab.active {
            background-color: #0366d6;
            color: white;
            border-color: #0366d6;
        }
        .content {
            display: none;
        }
        .content.active {
            display: block;
        }
    </style>
</head>
<body>
    <!-- 页眉 -->
    <header class="header">
        <div class="header-content">
            <a href="/" class="logo-link">
                <img src="https://cdn.jsdelivr.net/gh/dqzboy/Blog-Image/BlogCourse/docker-proxy.png" alt="Logo" class="logo">
            </a>
            <div class="menu-toggle" id="menuToggle">☰</div>
            <nav class="nav-menu" id="navMenu">
                <!-- 菜单项将通过 JavaScript 动态加载 -->
            </nav>
        </div>
    </header>

    <!-- 内容容器 -->
    <div class="container">
        <h1>Docker 镜像加速和镜像搜索</h1>
        <!-- 标签切换 -->
        <div class="tab-container">
            <div class="tab active" onclick="switchTab('accelerate')">镜像加速</div>
            <div class="tab" onclick="switchTab('search')">镜像搜索</div>
            <div class="tab" onclick="switchTab('documentation')">文档教程</div>
        </div>

        <!-- 镜像加速内容 -->
        <div id="accelerateContent" class="content active">
            <div class="input-group">
                <input type="text" id="imageInput" placeholder="请输入 Docker 镜像名称，例如：nginx 或 mysql:5.7">
                <button onclick="generateCommands(document.getElementById('imageInput').value.trim())">获取加速命令</button>
            </div>
            <!-- 结果容器 -->
            <div id="result" style="display:none;">
                <h2>加速命令</h2>
                <div id="commandsContainer"></div>
            </div>
        </div>

        <!-- 镜像搜索内容 -->
        <div id="searchContent" class="content">
            <div class="search-container">
                <input type="text" id="searchInput" placeholder="请输入 Docker 镜像名称进行搜索">
                <button onclick="searchDockerHub()">搜索Docker镜像</button>
            </div>
            <div id="searchResults"></div>
        </div>

         <!-- 文档教程内容 -->
         <div id="documentationContent" class="content">
            <div id="documentList"></div>
            <div id="documentationText"></div>
        </div>

        <!-- 广告容器 -->
        <div class="carousel" id="carousel">
            <div class="carousel-inner" id="carouselInner">
                <!-- 图片将在 JavaScript 中加载 -->
            </div>
            <div class="carousel-control left" onclick="prevSlide()">&#10094;</div>
            <div class="carousel-control right" onclick="nextSlide()">&#10095;</div>
        </div>
    </div>
    <!-- 页脚 -->
    <footer class="footer">
        <p>Copyright © <span id="currentYear"></span> All Rights Reserved. <a href="https://github.com/dqzboy/Docker-Proxy" target="_blank" rel="noopener noreferrer">Docker-Proxy</a> 版权所有</p>
    </footer>

    <!-- 返回顶部按钮 -->
    <button id="backToTopBtn" onclick="scrollToTop()">⌃</button>

    <script>
        // 设置当前年份
        document.getElementById('currentYear').textContent = new Date().getFullYear();

        document.addEventListener('DOMContentLoaded', (event) => {
            const menuToggle = document.getElementById('menuToggle');
            const navMenu = document.getElementById('navMenu');

            menuToggle.addEventListener('click', () => {
                navMenu.classList.toggle('active');
            });
        });
        
        let proxyDomain = ''; // 默认代理加速地址
        let currentIndex = 0;
        let items = [];

        // 标签切换功能
        function switchTab(tabName) {
            const tabs = document.querySelectorAll('.tab');
            const contents = document.querySelectorAll('.content');

            tabs.forEach(tab => tab.classList.remove('active'));
            contents.forEach(content => content.classList.remove('active'));

            document.querySelector(`.tab:nth-child(${tabName === 'accelerate' ? '1' : (tabName === 'search' ? '2' : '3')}`).classList.add('active');
            document.getElementById(`${tabName}Content`).classList.add('active');

            // 重置显示
            document.getElementById('searchResults').style.display = 'none';
            document.getElementById('result').style.display = 'none';
            document.getElementById('backToTopBtn').style.display = 'none';
            document.getElementById('carousel').style.display = 'flex'; // 默认显示广告

            if (tabName === 'documentation') {
                fetchDocumentation();
            } else if (tabName === 'accelerate') {
                const imageInput = document.getElementById('imageInput').value.trim();
                if (imageInput) {
                    generateCommands(imageInput);
                }
            } else if (tabName === 'search') {
                document.getElementById('searchInput').value = '';
            }
        }

        // 生成加速命令
        function generateCommands(imageInput) {
            if (!imageInput) {
                imageInput = document.getElementById('imageInput').value.trim();
            }
            if (!imageInput) {
                alert('请输入 Docker 镜像名称');
                return;
            }
            let [imageName, tag] = imageInput.split(':');
            tag = tag || 'latest';
            
            let originalImage = `${imageName}:${tag}`;
            let proxyImage = '';

            if (!imageName.includes('/')) {
                proxyImage = `${proxyDomain}/library/${imageName}:${tag}`;
            } else {
                proxyImage = `${proxyDomain}/${imageName}:${tag}`;
            }

            const commands = [
                { title: "原始拉取命令", cmd: `docker pull ${originalImage}` },
                { title: "代理拉取镜像", cmd: `docker pull ${proxyImage}` },
                { title: "重命名镜像", cmd: `docker tag ${proxyImage} ${originalImage}` },
                { title: "删除代理镜像", cmd: `docker rmi ${proxyImage}` }
            ];

            const resultDiv = document.getElementById('result');
            const container = document.getElementById('commandsContainer');
            container.innerHTML = '';

            // 将生成的命令添加到结果容器中
            commands.forEach((command, index) => {
                const cmdDiv = document.createElement('div');
                cmdDiv.className = 'step';
                cmdDiv.innerHTML = `
                    <h3>${index + 1}. ${command.title}</h3> <pre><code>${command.cmd}</code><div id="copyNotification${index}" class="notification">已复制!</div><button class="copy-btn" onclick="copyToClipboard('${command.cmd}', 'copyNotification${index}')">复制</button></pre>
                `;
                container.appendChild(cmdDiv);
            });

            // 显示结果并隐藏广告
            resultDiv.style.display = 'block';
            document.getElementById('carousel').style.display = 'none';
            document.getElementById('backToTopBtn').style.display = 'block';
        }

        // 复制命令到剪贴板
        function copyToClipboard(text, notificationId) {
            if (navigator.clipboard && navigator.clipboard.writeText) {
                navigator.clipboard.writeText(text).then(() => {
                    showNotification(notificationId);
                }, (err) => {
                    console.error('无法复制文本: ', err);
                });
            } else {
                const textarea = document.createElement('textarea');
                textarea.value = text;
                document.body.appendChild(textarea);
                textarea.select();
                document.execCommand('copy');
                document.body.removeChild(textarea);
                showNotification(notificationId);
            }
        }

        function showNotification(notificationId) {
            var notification = document.getElementById(notificationId);
            notification.style.display = 'block';
            notification.style.opacity = '1';

            // 在2秒后隐藏提示
            setTimeout(function() {
                notification.style.opacity = '0';
                setTimeout(function() {
                    notification.style.display = 'none';
                }, 500);
            }, 2000);
        }

        // 滚动到顶部
        function scrollToTop() {
            window.scrollTo({
                top: 0,
                behavior: 'smooth'
            });
        }

        let autoPlayTimer; // 用于存储自动播放的定时器

        // 更新轮播图
        function updateCarousel() {
            items.forEach((item, index) => {
                item.classList.remove('active', 'left', 'right');
                if (index === currentIndex) {
                    item.classList.add('active');
                } else if (index === (currentIndex - 1 + items.length) % items.length) {
                    item.classList.add('left');
                } else if (index === (currentIndex + 1) % items.length) {
                    item.classList.add('right');
                }
            });
        }

        function prevSlide() {
            currentIndex = (currentIndex - 1 + items.length) % items.length;
            updateCarousel();
            resetAutoPlay(); // 重置自动播放计时器
        }

        function nextSlide() {
            currentIndex = (currentIndex + 1) % items.length;
            updateCarousel();
            resetAutoPlay(); // 重置自动播放计时器
        }

        // 开始自动播放
        function startAutoPlay() {
            autoPlayTimer = setInterval(nextSlide, 10000); // 每10秒自动切换到下一张
        }
 
        // 重置自动播放计时器
        function resetAutoPlay() {
            clearInterval(autoPlayTimer);
            startAutoPlay();
        }

        // 搜索功能
        async function searchDockerHub() {
            const searchTerm = document.getElementById('searchInput').value.trim();
            if (!searchTerm) {
                alert('请输入搜索关键词');
                return;
            }

            const searchResults = document.getElementById('searchResults');
            searchResults.innerHTML = '正在搜索...';

            // 显示和隐藏广告逻辑
            searchResults.style.display = 'block';
            document.getElementById('result').style.display = 'none';
            document.getElementById('carousel').style.display = 'none';
            document.getElementById('backToTopBtn').style.display = 'block';

            try {
                const response = await fetch(`/api/search?term=${encodeURIComponent(searchTerm)}`);
                const data = await response.json();

                if (data.results && data.results.length > 0) {
                    const officialImages = data.results.filter(result => result.is_official);
                    const unofficialImages = data.results.filter(result => !result.is_official)
                        .sort((a, b) => (b.star_count || 0) - (a.star_count || 0))
                        .slice(0, 5);

                    searchResults.innerHTML = '';
                    
                    // 显示官方镜像
                    officialImages.forEach(result => {
                        searchResults.appendChild(createResultItem(result, true));
                    });

                    // 显示前5个非官方镜像
                    unofficialImages.forEach(result => {
                        searchResults.appendChild(createResultItem(result, false));
                    });

                    if (officialImages.length === 0 && unofficialImages.length === 0) {
                        searchResults.innerHTML = '未找到匹配的镜像';
                    }
                } else {
                    searchResults.innerHTML = '未找到匹配的镜像';
                }
            } catch (error) {
                console.error('搜索出错:', error);
                searchResults.innerHTML = '搜索时发生错误，请稍后重试';
            }
        }

        function createResultItem(result, isOfficial) {
            const resultItem = document.createElement('div');
            resultItem.className = `search-result-item ${isOfficial ? 'official-image' : ''}`;
            
            const officialBadge = isOfficial ? '<span class="official-badge">官方</span>' : '';
            const stars = result.star_count !== undefined ? `<span class="stars">★ ${result.star_count}</span>` : '';

            resultItem.innerHTML = `
                <h3>${result.name || result.repo_name || '未知名称'} ${officialBadge}</h3>
                <p>描述: ${result.description || result.short_description || '无描述'}</p>
                <p>${stars}</p>
                <button class="use-image-btn" onclick="useImage('${result.name || result.repo_name || ''}')">使用此镜像</button>
            `;
            return resultItem;
        }

        function useImage(imageName) {
            if (imageName) {
                document.getElementById('imageInput').value = imageName;
                switchTab('accelerate');
                // 直接生成加速命令，无需用户再次点击
                generateCommands(imageName);
            } else {
                alert('无效的 Docker 镜像名称');
            }
        }


        async function fetchDocumentation() {
            try {
                const response = await fetch('/api/documentation');
                if (!response.ok) {
                    throw new Error(`HTTP error! status: ${response.status}`);
                }
                const documents = await response.json();
                console.log('Fetched documents:', documents);

                const documentList = window.document.getElementById('documentList');
                const documentationText = window.document.getElementById('documentationText');
                
                if (Array.isArray(documents) && documents.length > 0) {
                    documentList.innerHTML = '<h2>文档列表</h2>';
                    const ul = window.document.createElement('ul');
                    documents.forEach(doc => {
                        if (doc && doc.id && doc.title) {
                            const li = window.document.createElement('li');
                            li.innerHTML = `<a href="javascript:void(0);" onclick="showDocument('${doc.id}')">${doc.title}</a>`;
                            ul.appendChild(li);
                        }
                    });
                    documentList.appendChild(ul);
                    
                    // 默认显示第一篇文档
                    if (documents[0] && documents[0].id) {
                        showDocument(documents[0].id);
                    } else {
                        documentationText.innerHTML = '无法显示文档，文档 ID 无效';
                    }
                } else {
                    documentationText.innerHTML = '暂无文档内容';
                }
                window.document.getElementById('carousel').style.display = 'none';
            } catch (error) {
                console.error('获取文档列表失败:', error);
                const documentationText = window.document.getElementById('documentationText');
                documentationText.innerHTML = '加载文档列表失败，请稍后再试。错误详情: ' + error.message;
                window.document.getElementById('carousel').style.display = 'flex';
            }
        }

        async function showDocument(id) {
            try {
                console.log('Attempting to show document with id:', id);
                const response = await fetch(`/api/documentation/${id}`);
                if (!response.ok) {
                    throw new Error(`HTTP error! status: ${response.status}`);
                }
                const document = await response.json();
                console.log('Fetched document:', document);

                const documentationText = window.document.getElementById('documentationText');
                
                if (document && document.content && document.content.trim() !== '') {
                    documentationText.innerHTML = `<h2>${document.title || '无标题'}</h2>` + marked.parse(document.content);
                } else {
                    documentationText.innerHTML = '该文档没有内容或格式不正确';
                }
            } catch (error) {
                console.error('获取文档内容失败:', error);
                const documentationText = window.document.getElementById('documentationText');
                documentationText.innerHTML = '加载文档内容失败，请稍后再试。错误详情: ' + error.message;
            }
        }

        // 获取并加载配置
        async function loadConfig() {
            try {
                const response = await fetch('/api/config');
                const config = await response.json();

                if (config.adImages && Array.isArray(config.adImages)) {
                    const carouselInner = document.getElementById('carouselInner');
                    carouselInner.innerHTML = ''; // 清空广告容器
                    config.adImages.forEach((ad, index) => {
                        const adItem = document.createElement('div');
                        adItem.className = 'carousel-item';
                        if (index === 0) {
                            adItem.classList.add('active');
                        }
                        const adImage = document.createElement('img');
                        adImage.src = ad.url;
                        adImage.alt = ad.alt || '广告图片';
                        adImage.style.width = "100%";
                        adImage.style.height = "100%";
                        adItem.appendChild(adImage);
                        carouselInner.appendChild(adItem);

                        // 添加点击事件监听器
                        adItem.addEventListener('click', function() {
                            window.open(ad.link, '_blank');
                        });

                        // 改变鼠标样式，表明可以点击
                        adItem.style.cursor = 'pointer';
                    });
                    items = document.querySelectorAll('.carousel-item');
                    updateCarousel();
                    startAutoPlay(); // 启动自动播放
                }
                if (config.logo) {
                    document.querySelector('.logo').src = config.logo;
                }
                if (config.menuItems && Array.isArray(config.menuItems)) {
                    const navMenu = document.getElementById('navMenu');
                    navMenu.innerHTML = ''; // 清空菜单
                    config.menuItems.forEach(item => {
                        const a = document.createElement('a');
                        a.href = item.link;
                        a.textContent = item.text;
                        if (item.newTab) {
                            a.target = '_blank';
                        }
                        navMenu.appendChild(a);
                    });
                }
                if (config.adImages && Array.isArray(config.adImages)) {
                    const carouselInner = document.getElementById('carouselInner');
                    carouselInner.innerHTML = ''; // 清空广告容器
                    config.adImages.forEach((ad, index) => {
                        const adItem = document.createElement('div');
                        adItem.className = 'carousel-item';
                        if (index === 0) {
                            adItem.classList.add('active');
                        }
                        const adImage = document.createElement('img');
                        adImage.src = ad.url;
                        adImage.alt = ad.alt || '广告图片';
                        adImage.style.width = "100%";
                        adImage.style.height = "100%";
                        adItem.appendChild(adImage);
                        carouselInner.appendChild(adItem);

                        // 添加点击事件监听器
                        adItem.addEventListener('click', function() {
                            window.open(ad.link, '_blank');
                        });

                        // 改变鼠标样式，表明可以点击
                        adItem.style.cursor = 'pointer';
                    });
                    items = document.querySelectorAll('.carousel-item');
                    updateCarousel();
                    startAutoPlay(); // 启动自动播放
                }
                if (config.proxyDomain) {
                    proxyDomain = config.proxyDomain;
                }
                // 添加对搜索API的支持
                if (config.searchApiEndpoint) {
                    window.searchApiEndpoint = config.searchApiEndpoint;
                }
            } catch (error) {
                console.error('加载配置失败:', error);
            }
            switchTab('accelerate');
        }

        loadConfig();
        // 当页面不可见时暂停自动播放，可见时恢复
        document.addEventListener("visibilitychange", function() {
            if (document.hidden) {
                clearInterval(autoPlayTimer);
            } else {
                startAutoPlay();
            }
        });
    </script>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/marked/2.0.3/marked.min.js"></script>
</body>
</html>